package com.mytest.DynamicProxy;

import net.sf.cglib.proxy.Enhancer;
import org.junit.Test;

import java.lang.reflect.Proxy;

public class DemoTest {

    /*
    * jdk动态代理好像没有生成新类，而cglib动态代理生成了新类
    * */
    @Test
    public void test1(){

        /*CF cf = new CF();
        TGP tgp = new TGP(cf);
        Game game = (Game) Proxy.newProxyInstance(cf.getClass().getClassLoader(),cf.getClass().getInterfaces(),tgp);
        game.play();*/

        LOL lol = new LOL();
        TGP tgp1 = new TGP(lol);
        Game game1 = (Game) Proxy.newProxyInstance(lol.getClass().getClassLoader(),lol.getClass().getInterfaces(),tgp1);
        game1.play();
    }

    @Test
    public void test2(){

        Enhancer enhancer = new Enhancer();
        LOL lol = new LOL();
        LOLMethodInterceptor lolMethodInterceptor = new LOLMethodInterceptor();
        enhancer.setSuperclass(lol.getClass());
        enhancer.setCallback(lolMethodInterceptor);
        LOL lol1 = (LOL) enhancer.create();

        lol.play();
        lol1.play();
    }


}
